// Compile with:
// g++ -std=gnu++0x example.cpp -o example-client-cpp11

//#define _CRT_SECURE_NO_WARNINGS
#include "../tool/wsclient.h"
#ifdef _WIN32
#pragma comment( lib, "ws2_32" )
#include <WinSock2.h>
#endif
#include <stdio.h>
#include <iostream>
void callback(void * pUser, const char * message, int len, int type)
{
	if (type == ws_text)
	{
		string str(message, len);
		std::cout <<"recv->"<< str << endl;
	}
	else if (type == ws_binary)
	{
		std::cout << "the binary len is " << len << endl;
	}
}


int main()
{
	c_ws_class::InitSock();
	c_ws_class ws;
	ws.set_url("ws://localhost:8000/live");
	if (ws.connect() !=0)
	{
		printf("connect is failure");
		return 0;
	}
	ws.Start(callback);
	
	ws.send("c1:abc\npass\nlive");
	char buffer[256];
	for (int i = 0; i < 100; i++)
	{
		sprintf(buffer, "this is %d\n", i);
		ws.send(buffer);
		std::this_thread::sleep_for(std::chrono::milliseconds(10));
	}
	
	ws.Join();
     
    return 0;
}
